package com.wt.controller;

import com.wt.Pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/userC")
public class ConsumerController {
    private final String  URL = "http://localhost:8084/userP";
    @Autowired
    private RestTemplate restTemplate;

    @PostMapping
    public String Add(User user){
        System.out.println("------添加--------");
        System.out.println("ConsumerAdd=="+user);
        String s = restTemplate.postForObject(URL, user, String.class);
        return s;
    }

    @DeleteMapping("/{id}")
    public String del(@PathVariable("id") Integer id){
        System.out.println("ConsumerDel=="+id);
        restTemplate.delete(URL+"/"+id);
        return "ok Del";
    }

    @GetMapping
    public String Get(User user){
        System.out.println("ConsumerGet=="+user);
        String s = restTemplate.getForObject(URL, String.class, user);
        return s;
    }

    @PutMapping
    public String Put(User user){
        System.out.println("ConsumerPut=="+user);
        return "ok Put";
    }
}
